package Year22_Month05.day10;

import java.util.Stack;

public class 用栈实现队列 {
    Stack<Integer> a;
    Stack<Integer> b;

    public 用栈实现队列() {
        a = new Stack();//用来入队
        b = new Stack();//用来出队
    }

    public void push(int x) {

        a.push(x);
    }

    public int pop() {
        while(b.empty()){
            while(!a.empty()){
                b.push(a.pop());
            }
        }
        return b.pop();
    }

    public int peek() {
        while(b.empty()){
            while(!a.empty()){
                b.push(a.pop());
            }
        }
        return b.peek();
    }

    public boolean empty() {
        return a.empty() && b.empty();
    }
}
